//
//  UIBarButtonItem+TaoJExtension_h.m
//  百思不得姐2
//
//  Created by 陶建 on 15/7/22.
//  Copyright (c) 2015年 taoJ. All rights reserved.
//

#import "UIBarButtonItem+TExtension.h"
#import <UIKit/UIKit.h>

@implementation UIBarButtonItem (TExtension)

/**
 *  快速创建一个UIBarButtonItem
 *
 *  @param image         Normal -> 图片
 *  @param selectedImage Highlighted -> 图片
 *  @param target        监听事件的目标对象
 *  @param sel           目标对象的方法
 *
 *  @return 创建好的UIBarButtonItem
 */
+ (instancetype)itemWithImage:(NSString *)image selectedImage:(NSString *)selectedImage target:(id)target action:(SEL)sel
{
    // 创建一个按钮，用来显示
    UIButton *newButton = [UIButton buttonWithType:UIButtonTypeCustom];
    // 设置normal下的图片
    [newButton setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    // 设置highlight下的图片
    [newButton setBackgroundImage:[UIImage imageNamed:selectedImage] forState:UIControlStateHighlighted];
    // 设置监听方法
    [newButton addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    // 按钮大小
    CGRect rect = newButton.frame;
    rect.size = newButton.currentBackgroundImage.size;
    newButton.frame = rect;

    return [[self alloc] initWithCustomView:newButton];
}
@end
